package com.ruoyi.cust.service.impl;

import java.util.List;
        import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.cust.mapper.CityProjectMapper;
import com.ruoyi.cust.domain.CityProject;
import com.ruoyi.cust.service.ICityProjectService;

/**
 * 项目Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-06
 */
@Service
public class CityProjectServiceImpl implements ICityProjectService {
    @Autowired
    private CityProjectMapper cityProjectMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 查询项目-管理平台
     *
     * @param projectId 项目主键
     * @return 项目  -管理平台查询详情
     */
    @Override
    public CityProject selectCityProjectByProjectId(Long projectId) {
        return cityProjectMapper.selectCityProjectByProjectId(projectId);
    }

    /**
     * 查询项目-写入缓存记录
     *
     * @param projectId 项目主键
     * @return 项目
     */
    @Override
    public CityProject selectAppProjectByProjectId(Long userId,Long projectId) {
        CityProject cityProject = cityProjectMapper.selectJoinById(projectId);
        //记录被查看的项目，用于后续查看我的历史记录
        String projectHisKey = "myProjectHis_"+userId;
        cityProject.setViewTime(DateUtils.getNowDate());
        redisTemplate.opsForList().leftPush(projectHisKey,cityProject);
        return cityProject;
    }

    @Override // com.ruoyi.system.service.city.ICityProjectService
    public List<CityProject> selectCollectCityProjectList(Long userId,String searchValue) {
        return this.cityProjectMapper.selectCollectCityProjectList(userId,searchValue);
    }

    @Override // com.ruoyi.system.service.city.ICityProjectService
    public List<CityProject> selectShareCityProjectList(Long userId,String searchValue) {
        return this.cityProjectMapper.selectShareCityProjectList(userId,searchValue);
    }

    /**
     * 查询项目列表
     *
     * @param cityProject 项目
     * @return 项目
     */
    @Override
    public List<CityProject> selectCityProjectList(CityProject cityProject) {
        return cityProjectMapper.selectCityProjectList(cityProject);
    }

    /**
     * 新增项目
     *
     * @param cityProject 项目
     * @return 结果
     */
    @Override
    public int insertCityProject(CityProject cityProject) {
                cityProject.setCreateTime(DateUtils.getNowDate());
            return cityProjectMapper.insertCityProject(cityProject);
    }

    /**
     * 修改项目
     *
     * @param cityProject 项目
     * @return 结果
     */
    @Override
    public int updateCityProject(CityProject cityProject) {
        return cityProjectMapper.updateCityProject(cityProject);
    }

    /**
     * 批量删除项目
     *
     * @param projectIds 需要删除的项目主键
     * @return 结果
     */
    @Override
    public int deleteCityProjectByProjectIds(Long[] projectIds) {
        return cityProjectMapper.deleteCityProjectByProjectIds(projectIds);
    }

    /**
     * 删除项目信息
     *
     * @param projectId 项目主键
     * @return 结果
     */
    @Override
    public int deleteCityProjectByProjectId(Long projectId) {
        return cityProjectMapper.deleteCityProjectByProjectId(projectId);
    }

    @Override
    public List<CityProject> selectCityProjectListByKeyword(String storeType,String searchInfo) {
        return cityProjectMapper.selectCityProjectListByKeyword(storeType,searchInfo);
    }

    @Override
    public List<CityProject> selectJoinList(CityProject cityProject) {
        return cityProjectMapper.selectJoinList(cityProject);
    }

    @Override
    public CityProject selectJoinById(Long projectId) {
        return cityProjectMapper.selectJoinById(projectId);
    }

    @Override
    public List<CityProject> listHotSearch(String storeType) {
        return cityProjectMapper.listHotSearch(storeType);
    }
}
